<!--
 * @Description: 
 * @Date: 2020-12-21 09:51:58
 * @LastEditors: lother
 * @LastEditTime: 2021-01-12 17:57:05
 * @FilePath: \AccountOpening-H5\src\components\page\k-row.vue
-->
<template>
    <div>
        <div v-for="(item,index) in listItem" :key="index">
            <k-firstTitle :val="item['title_'+langSuff]" v-if="item.type=='firstTitle'" />
            <k-textarea :val="item['title_'+langSuff]" v-if="item.type=='textarea' || item.type=='editor'" />
            <k-input :val.sync="form[item.name]" :list="item" v-if="item.type=='input'"/>
            <k-date :val.sync="form[item.name]" :list="item" :showTime="showTime" v-if="item.type=='datetime'" />
            <k-date :val.sync="form[item.name]" :list="item" :showTime="showTime" v-if="item.type=='date'" />
            <k-select :val.sync="form[item.name]" :list="item" v-if="item.type=='select'" />
            <k-switch :val.sync="form[item.name]"   :list="item" v-if="item.type=='switch'" />
            <k-radio  :val.sync='form[item.name]' :list="item" v-if="item.type=='radio'" />
            <k-checkbox  :val.sync='form[item.name]' :list="item" v-if="item.type=='checkbox'" />
            <k-identCards :val.sync="form[item.name]" :list="item" v-if="item.type=='identCards'" ></k-identCards>
            <k-upload :val.sync="form[item.name]" :list="item" v-if="item.type=='upload'"></k-upload>
            <k-row :defaultValue="form[item.keyName]" :value="item.keyValue" :list="item" :formItem.sync="form" v-if="item.type=='row' && showRow(form[item.config.keyName],item.config.keyValue , item.config.keyName)"></k-row>
        </div>
    </div>
</template>
<script>
export default { 
    name:"k-row",
    props:{
        list:{
            type:Object,
            default:()=>{}
        },
        formItem:{
            type:Object,
            default:()=>{}
        }
    },
    computed:{
        langSuff(){
            return  this.$store.state.langSuff
        },
        show(){
            
        },
        listItem(){
            var list
            if(typeof this.list?.container =='object'){
                list = this.list?.container || []
            }else if(typeof this.list?.container =='string'){
                list = JSON.parse(this.list?.container) || []
            }
            return list
        },
        form:{
            get(){
                return this.formItem
            },
            set(val){

                console.log(val)
            }
        }
    },
    data() {
        return {
            showTime:{min:11 ,max:18},
        }
    },
    methods:{
         showRow(defaultValue,val , defaultKey){
            // defaultValue  关联字段选择的值
            // val  后台返回的值
            // defaultKey 关联字段的key
            var list   =  this.listItem.find(item=> item.name == defaultKey )
            if(list && list.type=='identCards' && defaultValue && defaultValue !==''){
                return true
            }
            if((defaultValue && val) && defaultValue == val){
                return true
            }else{
                return false
            }
        },
    }
}
</script>